home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / JTextPane.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  5.1 KB  |  189 lines

  1. package javax.swing;
  2.  
  3. import java.awt.Component;
  4. import java.io.IOException;
  5. import java.io.ObjectOutputStream;
  6. import javax.swing.text.AttributeSet;
  7. import javax.swing.text.BadLocationException;
  8. import javax.swing.text.Caret;
  9. import javax.swing.text.Document;
  10. import javax.swing.text.EditorKit;
  11. import javax.swing.text.Element;
  12. import javax.swing.text.JTextComponent;
  13. import javax.swing.text.MutableAttributeSet;
  14. import javax.swing.text.Style;
  15. import javax.swing.text.StyleConstants;
  16. import javax.swing.text.StyledDocument;
  17. import javax.swing.text.StyledEditorKit;
  18.  
  19. public class JTextPane extends JEditorPane {
  20.    private static final String uiClassID = "TextPaneUI";
  21.  
  22.    public JTextPane() {
  23.       this.setEditorKit(new StyledEditorKit());
  24.    }
  25.  
  26.    public JTextPane(StyledDocument var1) {
  27.       this();
  28.       this.setStyledDocument(var1);
  29.    }
  30.  
  31.    public Style addStyle(String var1, Style var2) {
  32.       StyledDocument var3 = this.getStyledDocument();
  33.       return var3.addStyle(var1, var2);
  34.    }
  35.  
  36.    protected EditorKit createDefaultEditorKit() {
  37.       return new StyledEditorKit();
  38.    }
  39.  
  40.    public AttributeSet getCharacterAttributes() {
  41.       StyledDocument var1 = this.getStyledDocument();
  42.       Element var2 = var1.getCharacterElement(((JTextComponent)this).getCaretPosition());
  43.       return var2 != null ? var2.getAttributes() : null;
  44.    }
  45.  
  46.    public MutableAttributeSet getInputAttributes() {
  47.       return this.getStyledEditorKit().getInputAttributes();
  48.    }
  49.  
  50.    public Style getLogicalStyle() {
  51.       StyledDocument var1 = this.getStyledDocument();
  52.       return var1.getLogicalStyle(((JTextComponent)this).getCaretPosition());
  53.    }
  54.  
  55.    public AttributeSet getParagraphAttributes() {
  56.       StyledDocument var1 = this.getStyledDocument();
  57.       Element var2 = var1.getParagraphElement(((JTextComponent)this).getCaretPosition());
  58.       return var2 != null ? var2.getAttributes() : null;
  59.    }
  60.  
  61.    public boolean getScrollableTracksViewportWidth() {
  62.       return true;
  63.    }
  64.  
  65.    public Style getStyle(String var1) {
  66.       StyledDocument var2 = this.getStyledDocument();
  67.       return var2.getStyle(var1);
  68.    }
  69.  
  70.    public StyledDocument getStyledDocument() {
  71.       return (StyledDocument)((JTextComponent)this).getDocument();
  72.    }
  73.  
  74.    protected final StyledEditorKit getStyledEditorKit() {
  75.       return (StyledEditorKit)((JEditorPane)this).getEditorKit();
  76.    }
  77.  
  78.    public String getUIClassID() {
  79.       return "TextPaneUI";
  80.    }
  81.  
  82.    public void insertComponent(Component var1) {
  83.       MutableAttributeSet var2 = this.getInputAttributes();
  84.       var2.removeAttributes(var2);
  85.       StyleConstants.setComponent(var2, var1);
  86.       this.replaceSelection(" ");
  87.       var2.removeAttributes(var2);
  88.    }
  89.  
  90.    public void insertIcon(Icon var1) {
  91.       MutableAttributeSet var2 = this.getInputAttributes();
  92.       var2.removeAttributes(var2);
  93.       StyleConstants.setIcon(var2, var1);
  94.       this.replaceSelection(" ");
  95.       var2.removeAttributes(var2);
  96.    }
  97.  
  98.    protected String paramString() {
  99.       return super.paramString();
  100.    }
  101.  
  102.    public void removeStyle(String var1) {
  103.       StyledDocument var2 = this.getStyledDocument();
  104.       var2.removeStyle(var1);
  105.    }
  106.  
  107.    public void replaceSelection(String var1) {
  108.       if (!((JTextComponent)this).isEditable()) {
  109.          ((Component)this).getToolkit().beep();
  110.       } else {
  111.          StyledDocument var2 = this.getStyledDocument();
  112.          if (var2 != null) {
  113.             try {
  114.                Caret var3 = ((JTextComponent)this).getCaret();
  115.                int var4 = Math.min(var3.getDot(), var3.getMark());
  116.                int var5 = Math.max(var3.getDot(), var3.getMark());
  117.                if (var4 != var5) {
  118.                   var2.remove(var4, var5 - var4);
  119.                }
  120.  
  121.                if (var1 != null && var1.length() > 0) {
  122.                   var2.insertString(var4, var1, this.getInputAttributes());
  123.                }
  124.             } catch (BadLocationException var6) {
  125.                ((Component)this).getToolkit().beep();
  126.             }
  127.          }
  128.  
  129.       }
  130.    }
  131.  
  132.    public void setCharacterAttributes(AttributeSet var1, boolean var2) {
  133.       int var3 = ((JTextComponent)this).getSelectionStart();
  134.       int var4 = ((JTextComponent)this).getSelectionEnd();
  135.       if (var3 != var4) {
  136.          StyledDocument var5 = this.getStyledDocument();
  137.          var5.setCharacterAttributes(var3, var4 - var3, var1, var2);
  138.       } else {
  139.          MutableAttributeSet var6 = this.getInputAttributes();
  140.          if (var2) {
  141.             var6.removeAttributes(var6);
  142.          }
  143.  
  144.          var6.addAttributes(var1);
  145.       }
  146.  
  147.    }
  148.  
  149.    public void setDocument(Document var1) {
  150.       if (var1 instanceof StyledDocument) {
  151.          super.setDocument(var1);
  152.       } else {
  153.          throw new IllegalArgumentException("Model must be StyledDocument");
  154.       }
  155.    }
  156.  
  157.    public final void setEditorKit(EditorKit var1) {
  158.       if (var1 instanceof StyledEditorKit) {
  159.          super.setEditorKit(var1);
  160.       } else {
  161.          throw new IllegalArgumentException("Must be StyledEditorKit");
  162.       }
  163.    }
  164.  
  165.    public void setLogicalStyle(Style var1) {
  166.       StyledDocument var2 = this.getStyledDocument();
  167.       var2.setLogicalStyle(((JTextComponent)this).getCaretPosition(), var1);
  168.    }
  169.  
  170.    public void setParagraphAttributes(AttributeSet var1, boolean var2) {
  171.       int var3 = ((JTextComponent)this).getSelectionStart();
  172.       int var4 = ((JTextComponent)this).getSelectionEnd();
  173.       StyledDocument var5 = this.getStyledDocument();
  174.       var5.setParagraphAttributes(var3, var4 - var3, var1, var2);
  175.    }
  176.  
  177.    public void setStyledDocument(StyledDocument var1) {
  178.       super.setDocument(var1);
  179.    }
  180.  
  181.    private void writeObject(ObjectOutputStream var1) throws IOException {
  182.       var1.defaultWriteObject();
  183.       if (super.ui != null && this.getUIClassID().equals("TextPaneUI")) {
  184.          super.ui.installUI(this);
  185.       }
  186.  
  187.    }
  188. }
  189.